package net.scribblemedia.sqldsk.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.springframework.roo.addon.entity.RooEntity;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooEntity(finders = { "findReportRowsByRowHashEquals", "findReportRowsByReportQueryAndRowHash" })
public class ReportRow {

    @ManyToOne
    private ReportQuery reportQuery;

    private ReportRowState reportRowState;
    
    private boolean archived;

    @OneToMany(cascade = { CascadeType.ALL })
    private List<ReportRowColumn> reportRowColumns;

    private String rowHash;

    @OneToMany(cascade = { CascadeType.ALL })
    private List<Comment> comments;

    public void addReportRowColumn(ReportRowColumn reportRowColumn) {
        if (reportRowColumns == null) {
            reportRowColumns = new ArrayList<ReportRowColumn>();
        }
        reportRowColumns.add(reportRowColumn);
        reportRowColumn.setReportRow(this);
    }
    
    public void addComment(Comment comment) {
        if (comments == null) {
            comments = new ArrayList<Comment>();
        }
        comments.add(comment);
        comment.setReportRow(this);
    }

	public void removeComment(Comment comment) {
		comments.remove(comment);
		comment.setReportRow(null);
	}
}
